<template>
	<!-- 补贴 -->
	<view class="pl20 pr20 pb60">
		<view class="boxr pl20 pr20 mt26 tr">
			<u-form :model="form" ref="uForm" label-width='auto'>
				<u-form-item label="姓名:" prop="name">
					<u-input v-model="form.name" placeholder="请输入你的姓名" />
				</u-form-item>
				<u-form-item label="性别:" prop="gender">
					<u-input v-model="form.gender" @tap="setgender" placeholder="请选择你的性别" disabled />
					<view class="cuIcon-right" solt="right" @tap="setgender"></view>
				</u-form-item>
				<u-form-item label="联系电话:" prop="iphone">
					<u-input v-model="form.iphone" placeholder="请输入你的联系电话" />
				</u-form-item>
				<u-form-item label="身份证号:" prop="id_number">
					<u-input v-model="form.id_number" placeholder="请输入你的证件号码" />
				</u-form-item>
				<u-form-item label="地址:" prop="induction_place">
					<u-input v-model="form.induction_place" placeholder="请输入身份证地址" />
				</u-form-item>
				<u-form-item label="入职企业:" prop="induction_enterprise">
					<u-input v-model="form.induction_enterprise" placeholder="请输入入职企业" />
				</u-form-item>
				<u-form-item label="入职岗位:" prop="induction_post">
					<u-input v-model="form.induction_post" placeholder="请输入入职岗位" />
				</u-form-item>
				<u-form-item label="入职时间:" prop="induction_time">
					<u-input v-model="form.induction_time" @tap="show=true" placeholder="请选择入职时间" disabled />
					<view class="cuIcon-right" @tap="setstatus" solt="right"></view>
				</u-form-item>
				<u-form-item label="状态:" prop="enrollment_status">
					<u-input v-model="form.enrollment_status" @tap="setstatus" placeholder="请选择在职/离职状态" disabled />
					<view class="cuIcon-right" @tap="setstatus" solt="right"></view>
				</u-form-item>
				<u-form-item label="结算工时:" prop="induction_hours">
					<u-input v-model="form.induction_hours" placeholder="请输入结算工时" />
				</u-form-item>
				<u-form-item label="结算价:" prop="hours_piece">
					<u-input v-model="form.hours_piece" placeholder="请输入结算价" />
				</u-form-item>
				<u-form-item label="结算额:" prop="settlement_amount">
					<u-input v-model="form.settlement_amount" placeholder="请输入结算额" />
				</u-form-item>
			</u-form>
		</view>

		<!-- 补贴规则盒子 -->
		<view class="pt28 pl28 pb34 box-center mt26 pr30">
			<view class="mb28 box-center-top">
				*结算规则
			</view>
			<view class="box-center-b">
				<rich-text :nodes="subsidy_rule"></rich-text>
			</view>
		</view>
		<!-- /补贴规则盒子 -->

		<!-- 提交申请 -->
		<view class="footer-btn" @tap="submit">{{form.id?'修改':'提交'}}申请</view>
		<u-picker mode="time" @confirm="setTime" v-model="show"></u-picker>
	</view>
</template>

<script>
	export default {
		name:"jiesuan",
		data() {
			return {
				show: false,
				id:'',
				form: {
					name: '',
					gender: '',
					iphone: '',
					id_number: '',
					induction_enterprise: '',
					induction_post: '',
					induction_place: '',
					induction_time: '',
					induction_hours: '',
					enrollment_status: '',
					hours_piece: '',
					settlement_amount:'',
					id:''
				},
				// 性别选择
				actionSheetList: ['男', '女'],
				//控制性别弹层
				actionSheetShow: false,
				subsidy_rule:uni.getStorageSync('config').subsidy_rule
			};
		},
		onLoad(e) {
			if (e.id) {
				uni.setNavigationBarTitle({
					title: '修改申请'
				})
				this.id=e.id
				//获取详情的方法
				this.getsubsidyDetails()
				// let routes = getCurrentPages() //判断是不是在登录页
				// let curRoute = routes[routes.length - 2].data[e.index]
				// curRoute.induction_time = curRoute.induction_time_text
				// this.form = curRoute
				// console.log('000',this.form)
			}
		},
		methods: {
			//获取表单详情
			getsubsidyDetails() {
				this.$api.subsidyDetails({id:this.id}).then(res=>{
					console.log('111',res)
					this.form=res.data
				})
			},
			submit() {
				let api
				if (this.form.id) {
					api = 'subsidyEdit' //修改
				} else {
					api = 'subsidy' //提交
				}
				this.$api[api](this.form).then(res => {
					this.$msg(res.msg)
					setTimeout(() => {
						uni.navigateBack()
					}, 1000)
				})
			},
			setTime(e) {
				console.log(e);
				this.form.induction_time = "" + e.year + '-' + e.day + '-' + e.month
			},
			setgender() {
				let that = this
				let itemList = ['男', '女']
				uni.showActionSheet({
					itemList,
					success(res) {
						that.form.gender = itemList[res.tapIndex]
					}
				})
			},
			setstatus() {
				let that = this
				//请选择在职/离职状态
				let itemList = ['在职', '离职']
				uni.showActionSheet({
					itemList,
					success(res) {
						that.form.enrollment_status = itemList[res.tapIndex]
					}
				})
			},
			// 点击actionSheet回调
			actionSheetCallback(index) {
				console.log(1)
				uni.hideKeyboard();
				this.form.gender = this.actionSheetList[index].text;
			},
		},
		onNavigationBarButtonTap() {
			    uni.$once('update',(data)=>{
					console.log('111',JSON.parse(data))
					this.form=JSON.parse(data)
			    })
			this.$jump('/pages/home/subsidy/historyApply/historyApply')
		},
	}
</script>

<style lang="scss">
	/deep/.uni-input-wrapper {
		text-align: right !important;
	}

	.box-center {
		background: #F5F8FB;
		border: 2rpx solid #D2DEEB;
		border-radius: 6rpx;
		.box-center-top {
			font-size: 24rpx;
			color: #1385FF;
		}

		.box-center-b {
			font-size: 22rpx;
			font-weight: 500;
			color: #97A0AE;
		}
	}

	.footer-btn {
		margin: 0 auto;
		margin-top: 46rpx;
		width: 600rpx;
		height: 86rpx;
		background: #1385FF;
		border-radius: 10rpx;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #FFFFFF;
		line-height: 86rpx;
		text-align: center;
	}
</style>
